import { useRequest, useFetcher } from 'alova/client'
import { getTasks, getMyDayTasks, getTaskDetail, createTask, updateTask, deleteTask } from '../services/taskService'
import type { Task } from '../types/task'

// 获取任务列表
export const useTaskList = (params?: {
  group_id?: number
  status?: number
  is_important?: boolean
  is_my_day?: boolean
  page?: number
  page_size?: number
}) => {
  return useRequest(
    () => getTasks(params),
    {
      initialData: { list: [] as Task[], pagination: { page: 1, page_size: 10, total: 0 } },
      immediate: true
    }
  )
}

// 获取"我的一天"任务列表
export const useMyDayTasks = () => {
  return useRequest(
    () => getMyDayTasks(),
    {
      initialData: { list: [] as Task[], total: 0 },
      immediate: true
    }
  )
}

// 获取任务详情
export const useTaskDetail = (taskId: number) => {
  return useRequest(
    () => getTaskDetail(taskId),
    {
      initialData: {} as Task,
      immediate: !!taskId
    }
  )
}

// 创建任务
export const useCreateTask = () => {
  return useFetcher(() => createTask({} as any))
}

// 更新任务
export const useUpdateTask = () => {
  return useFetcher((taskId: number, data: any) => updateTask(taskId, data))
}

// 删除任务
export const useDeleteTask = () => {
  return useFetcher((taskId: number) => deleteTask(taskId))
}